#include <iostream>
#include <cstring>

using namespace std;
const int N = 110 , M = 10010;
int t[N] , w[N];
int n;
int dp[M];
int main()
{
    cin >> n;
    int sum = 0;
    for(int i = 1;i <= n;i ++)
    {
        cin >> t[i] >> w[i];
        sum += t[i];
    }
    memset(dp , 0x3f3f3f3f , sizeof dp);
    dp[0] = 0;
    for(int i = 1;i <= n;i ++)
    {
        for(int j = sum;j >= t[i];j --)
        {
            dp[j] = min(dp[j] , dp[j-t[i]] + w[i]);
        }
    }
    for(int j = sum;j >= 0;j--)
    {
        if(dp[j] <= sum - j)
        {
            cout << sum - j << endl;
            break;
        }
    }
    return 0;
}